package daobeauty.test.junit;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import daobeauty.proxy.ProxyFactory;
import daobeauty.test.HibernateSessionFactoryUtil;

public class BasicSetup {
	private Session session;
	private Transaction transaction;
	private SessionFactory sessionFactory;
	private ProxyFactory proxyFactory;
	
	public Session getSession() {
		return session;
	}
	
	public ProxyFactory getProxyFactory(){
		return proxyFactory;
	}
	
	public SessionFactory getSessionFactory(){
		return sessionFactory;
	}
	
	public void startup(){
		sessionFactory = HibernateSessionFactoryUtil.getSessionFactory();
		session = sessionFactory.getCurrentSession();
		transaction = session.beginTransaction();
		proxyFactory = new ProxyFactory();
	}
	
	public void shutdown(){
		transaction.rollback();
		if (session!=null){
			if (session.isOpen()){
				session.close();
			}
		}
	}
	
}
